//
//  WLMJRefresh.m
//  tubaobao
//
//  Created by 王亮 on 2017/12/7.
//  Copyright © 2017年 Rice. All rights reserved.
//

#import "WLMJRefresh.h"
@interface WLMJRefresh (){
}

@end
@implementation WLMJRefresh
+ (WLMJRefresh *)sharedMod {
    static dispatch_once_t hanwanjie;
    static WLMJRefresh *sharedView;
    //只执行一次
    dispatch_once(&hanwanjie, ^{
        sharedView = [[self alloc]init];
    });
    return sharedView;
}
-(NSMutableArray *)images{
    if (!_images) {
        _images = [NSMutableArray array];
        for (int i = 1; i<31 ; i++) {
            NSString *imageNmae = [NSString stringWithFormat:@"home_efresh_%d",i];
            UIImage *img = [UIImage imageNamed:imageNmae];
            if (img) {
                [_images addObject:img];
            }
        }
    }
    return _images;
}

-(NSMutableArray *)defaultLeafImages{
    if (!_defaultLeafImages) {
        _defaultLeafImages = [NSMutableArray array];
        for (int i = 1; i<31 ; i++) {
            NSString *imageNmae = [NSString stringWithFormat:@"home_efresh_%d",i];
            UIImage *img = [UIImage imageNamed:imageNmae];
            if (img) {
                [_defaultLeafImages addObject:img];
            }
        }
    }
    return _defaultLeafImages;
}

+(MJRefreshGifHeader *)refreshTarget:(id)target gifHeader:(SEL)sel{
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadNewData方法）
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:target refreshingAction:sel];
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = YES;
    // 设置普通状态的动画图片 (idleImages 是图片)
    [header setImages:[self sharedMod].images forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [header setImages:[self sharedMod].images forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [header setImages:[self sharedMod].images forState:MJRefreshStateRefreshing];
    return header;
}

+(MJRefreshStateHeader *)refreshHeaderTarget:(id)target refreshingAction:(SEL)sel{
//    MJRefreshNormalHeader //有箭头图片
    MJRefreshStateHeader *header = [MJRefreshStateHeader headerWithRefreshingTarget:target refreshingAction:sel];
    header.lastUpdatedTimeLabel.hidden = YES;
    
    return header;
}
+(MJRefreshAutoFooter *)refreshFootTarget:(id)target refreshingAction:(SEL)sel{
    return [MJRefreshAutoFooter footerWithRefreshingTarget:target refreshingAction:sel];
}
+(MJRefreshAutoFooter *)refreshAutoNormalFootTarget:(id)target refreshingAction:(SEL)sel{
//    return [MJRefreshAutoNormalFooter footerWithRefreshingTarget:target refreshingAction:sel];
    return [MJRefreshAutoFooter footerWithRefreshingTarget:target refreshingAction:sel];
}
@end
